<?php
namespace Admin\Controller;
use Think\Controller;
class AdminTypeController extends Controller {
    /**
     * 新闻分类首页展示
     * @return [type] [description]
     */
    public function newsindex(){
        $news_type = M('type');
        $sqlFather = "SELECT * FROM sv_type WHERE type_type = '1' && type_path = '0' ORDER BY type_order DESC;";
        $newsFatherDetail  = $news_type -> query($sqlFather);
        // var_dump($newsFatherDetail);
        // var_dump($newsChildDetail);
        // foreach ($newsFatherDetail as $key => $value) {
        //     var_dump($newsFatherDetail[$key]); 
        // }
        $this->assign('newsFatherDetail',$newsFatherDetail);
        $this->assign('newsChildDetail',$newsChildDetail);
        $this->assign('title','分类管理');
        $this->display();
    }
    function typeorder()
    {
        $news_type = M('type');
        $type_id = $_GET['type_id'];
        $type = I("type");
        $type_order = I("type_order");
        if ($type == 'up') {
            // echo json_encode($type_order);
            $type_order = $type_order + 1;
            $sqlOrderUp = "UPDATE sv_type SET type_order = '".$type_order."' WHERE type_id = '".$type_id."';";
            $news_type -> query($sqlOrderUp);
            $sqlFather = "SELECT * FROM sv_type WHERE type_type = '1' ORDER BY type_order;";
            $newsFatherDetail  = $news_type -> query($sqlFather);
            echo json_encode($newsFatherDetail);
        }else if($type == 'down'){
            if ($type_order == 0) {
                die();
            }
            $type_order = $type_order - 1;
            $sqlOrderDown = "UPDATE sv_type SET type_order = '".$type_order."' WHERE type_id = '".$type_id."';";
            $news_type -> query($sqlOrderDown);
            // echo json_encode($type_id);
        }
        // echo json_encode("111");
    }
    public function AddType()
    {
        
    }
}